const app = getApp()
const db = wx.cloud.database()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    openid: "",
    userPhoto: "",
    nickName: " ",
    logged: "false",
    disabled: true,

    shenfentype: wx.getStorageSync('user').xinwentype
  },

  // 生命周期onShow()
  onShow: function () {
    this.setData({
      openid:wx.getStorageSync('openid')
    })
    db.collection('users').where({
      zhanghao: wx.getStorageSync('user').zhanghao,
      mima: wx.getStorageSync('user').mima,
    }).get().then((res) => {
      console.log(res);
      if (res.data.length) {
        app.userInfo = Object.assign(app.userInfo, res.data[0]);
        this.setData({
          userPhoto: app.userInfo.userPhoto,
          nickName: app.userInfo.nickName,
          logged: true,
        })
      } else {
        this.setData({
          disabled: false
        })
      }
    })
  },

  onLoad() {
    this.setData({
      shenfentype: wx.getStorageSync('user').xinwentype
    })
  },
  tuichu() {

    wx.setStorageSync('user', '')
    wx.redirectTo({
      url: '../shouye/index',
    })
  }


})